package com.eascs.web.o2o.web.aging.utils;

import java.util.List;

import com.eascs.app.dao.PageResult;

public class IntToDate {
	
	public static PageResult<Object[]> toDate(PageResult<Object[]> agingInfoByPage, int startIndex, int endIndex) {
		List<Object[]> data = agingInfoByPage.getData();
		int len = data.size() ;
		if (len > 0) {
			for (int i = 0; i < len; i++) {
				for (int j = startIndex; j <= endIndex; j++) {
					String time = null;
					if (!(data.get(i)[j] instanceof String)) {
						time =  String.valueOf(data.get(i)[j]);
					}
					time = data.get(i)[j] == null ? "0" :time;
					data.get(i)[j] = secToTime(time);
				}
			}
		}
		return agingInfoByPage;
	}
	public static String secToTime(String times) {  
		float time = Float.parseFloat(times);
        String timeStr = null;
        int hour = 0;  
        int minute = 0;  
        int second = 0;  
        hour = (int) Math.floor(time);
        float temp = time - hour ;
        minute = (int) Math.floor(temp*60);
        temp = temp*60 - minute;
        second = (int) Math.rint(temp*60);
        timeStr = unitFormat(hour) + ":" + unitFormat(minute) + ":" + unitFormat(second);
        return timeStr;  
    }  
  
    public static String unitFormat(int i) { 
    	if (i <= 0) {
    		i = 0;
    	}
        String retStr = null;  
        if (i >= 0 && i < 10)  
            retStr = "0" + Integer.toString(i);  
        else  
            retStr = "" + i;  
        return retStr;  
    }  
}
